<?php
App::uses('Usuario', 'Model');

/**
 * Empresa Test Case
 *
 */
class UsuarioTestCase extends CakeTestCase {
/**
 * Fixtures
 *
 * @var array
 */
	public $fixtures = array("app.usuario");

/**
 * setUp method
 *
 * @return void
 */
	public function setUp() {
		parent::setUp();
		$this->Usuario = ClassRegistry::init('Usuario');
	}
	
	public function testSenhasIguais(){
		$this->Usuario->data['Usuario']['confirmar_senha'] = '1234';
		$data = array('senha'=>'1234');
		$this->assertTrue($this->Usuario->senhasIguais($data));
	}
	
	public function testSenhasIguaisSenhasDiferentes(){
		$this->Usuario->data['Usuario']['confirmar_senha'] = '12';
		$data = array('senha'=>'1234');
		$this->assertFalse($this->Usuario->senhasIguais($data));
	}
	
	public function testSenhasIguaisSenhaVazia(){
		$this->Usuario->data['Usuario']['confirmar_senha'] = '';
		$data = array('senha'=>'1234');
		$this->assertFalse($this->Usuario->senhasIguais($data));
	}
	
	public function testSaveUnico(){
		$this->Usuario->data['Usuario'] = array(
			'nome'=>'Willen',
			'senha'=>'senha',
			'senha_hash'=>"d5fe385b0303439b87fd254d59bc410ebceab0de",
			'email'=>'willen@gmail.com',
			'apelido'=>'unicoApelido'
		);
		$expected = array('Usuario' => array (
			"id" => 5,
            "nome" => "Willen",
            "email" => "willen@gmail.com",
            "senha" => "d5fe385b0303439b87fd254d59bc410ebceab0de",
            "reviews" => 0,
            "nota_media" => 0,
            "apelido" => "unicoApelido",
            "security_hash" => "",
			"ativo"=>0,
			"facebook"=>"",
			"twitter"=>"",
			"homepage"=>""
		));
		$this->Usuario->save();
		$result = $this->Usuario->find('first', array('conditions'=>array('id'=>$this->Usuario->id), 'recursive'=>-1));
		$this->assertEquals($result, $expected);
	}
	
	public function testAtivarConta(){
		$hash = "ativa";
		$this->assertTrue($this->Usuario->ativarConta($hash));
	}
	
	public function testAtivarContaAtiva(){
		$hash = "erro";
		$this->assertFalse($this->Usuario->ativarConta($hash));
	}
	
	public function testAtivarContaHashNaoExiste(){
		$hash = "naoExisteEsseHash";
		$this->assertFalse($this->Usuario->ativarConta($hash));
	}
	
	public function tearDown() {
		unset($this->Usuario);

		parent::tearDown();
	}
}
